package com.ac.zhly.service.impl;

import com.ac.zhly.model.param.LoginParam;
import com.ac.zhly.model.po.User;
import com.ac.zhly.mapper.UserMapper;
import com.ac.zhly.model.vo.UserVO;
import com.ac.zhly.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author AC
 * @since 2025-03-12
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserVO getUserInfo(LoginParam loginParam) {

        // 使用链式Lambda表达式查询数据库
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        log.info("loginParam: {}", loginParam);
        wrapper.eq(User::getPhone, loginParam.getPhone())
                .eq(User::getPassword, loginParam.getPassword());

        User user = userMapper.selectOne(wrapper);

        if (user != null) {
            // 将User对象封装到UserVO中
            UserVO userVO = new UserVO();
            userVO.setName(user.getName());
            userVO.setUuid(user.getUuid());
            userVO.setPhone(user.getPhone());
            // 根据需要添加其他字段
            return userVO;
        } else {
            return null;
        }
    }
}

